About 891 letters

About 4 minutes

#zip

Description: Combine multiple iterables into an iterable of tuples.

def zip(*iterables, strict=False):
    '''
    Combine multiple iterables into an iterable of tuples

    :param iterables: any number of iterables
    :param strict: whether to use strict mode
    :return: the combined iterable of tuples
    '''
  • In strict mode, all iterables must have the same length.
  • In non-strict mode, the combination is based on the shortest iterable length.

Example:

names = ['Tom', 'Jerry', 'Spike', 'Tuffy']
scores = [88, 99, 66, 33]
ages = [8, 7, 10]

print(zip(names, scores))
print(list(zip(names, scores)))

print(list(zip(names, ages)))
print(list(zip(names, ages, strict=True)))

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

Updated: 6/9/2025

Author: PlanC

Created: 6/9/2025